package com.lx.chong.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * Redis缓存设置通用过期时间
 *
 * @author: whh
 * @date: 2018/3/6
 */
@Configuration
@EnableCaching
public class RedisAutoConfig extends CachingConfigurerSupport {


    @Bean
    public CacheManager cacheManager(RedisTemplate redisTemplate) {
        RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
        //设置通用缓存过期时间
        //TODO 方便测试,上线前修改
//        rcm.setDefaultExpiration(3600 * 12L);
        rcm.setDefaultExpiration(1);
        return rcm;
    }
}
